var totalPage;
var totalCnt;
var log = [];

$(document).ready(function() {
	showLoading();
	$('title', parent.document).html($('title').text());
	setBaseUrl();
	setTimeout(hideLoading, 500);
});

function firstLog(){
	$("page").val(1);
	searchLog();
}
//日志查询
function searchLog(){
	showLoading();
	seach = 1;
	$.ajax({
		type: "POST",
		url: 'searchLog',
		dataType:'json',                  
		data : $("#searchlog").serialize(),		
		success: function(data){
			setTimeout(hideLoading, 500);
		    clearTable("logTbody");
		    totalPage = data && data.totalPage || 0;
		    totalCnt = data && data.totalCnt || 0;
			//当前页数
			var currentPage = $('#currentPage').val();
			var rows = $("#rows").val();
			document.getElementById("total").innerText = '共' + totalCnt + '条 / 共' + totalPage + '页';
			log = data.logList;
			//对应的表格ID
			var tbody=$("#logTbody");
			var length = userInfos.length;
			if (length == 0) {
				showMessge("没有查询结果");
			} else {
				for(var i=0; i<length; i++){
					var $tr = $('<tr>').appendTo(tbody);
					var rowNo = (currentPage - 1) * rows + i + 1;
					$("<td>").html(rowNo).appendTo($tr);
					$("<td>").html(log[0]).appendTo($tr);
					$("<td>").html("<a onclick=downloadLog();>下载</a>").appendTo($tr);
				}
			}
		},
		error: function(data){
			setTimeout(hideLoading, 500);
			if (data.status == "403" && data.statusText == "Forbidden") {
				showMessge("没有访问权限");
			} else {
				showMessge("查询失败!");
			}
		},
		timeout: function(data){
			setTimeout(hideLoading, 500);
			showMessge("操作超时！");
		}
	});
}
//日志文件下载
function downloadLog(){
	showLoading();
	$.ajax({
		type: "POST",
		url: 'downloadLog',
		dataType:'json',                  	
		success: function(data){
			setTimeout(hideLoading, 500);
			},
		error: function(data){
			setTimeout(hideLoading, 500);
			if (data.status == "403" && data.statusText == "Forbidden") {
				showMessge("没有访问权限");
			} else {
				showMessge("下载失败!");
			}
		},
		timeout: function(data){
			setTimeout(hideLoading, 500);
			showMessge("操作超时！");
		}
	});
}